{extend name="public:base"}
{block name='css'}
<link href="__PUBLIC__/css/plugins/iCheck/custom.css" rel="stylesheet">
{/block}
{block name="js"}
<script src="__PUBLIC__/js/plugins/peity/jquery.peity.min.js"></script>
<script src="__PUBLIC__/js/content.min.js?v=1.0.0"></script>
<script type="text/javascript">
    function setLocks(self) {
        if ($(self).hasClass('ed')) {
            return false;
        }

        var id = $(self).attr('data-id');
        var locks = $(self).attr('data-locks');

        $(self).addClass('ed');
        var obj = showMyLoading();
        $.post("{:url('locks')}", {id:id,locks:locks}, function(data){
            hideMyLoading(obj);
            layer.msg(data.info);
            if (data.status == 'y') {
                if (locks == 1) {
                    $(self).attr('class', 'btn btn-danger btn-xs delete').attr('data-locks', '0').text('是');
                } else {
                    $(self).attr('class', 'btn btn-success btn-xs edit').attr('data-locks', '1').text('否');
                }
            } else {
                $(self).removeClass('ed');
            }
        }, 'json');
    }
    function delAll(self){
        if ($(self).hasClass('ed')) {
            return false;
        }
        layer.confirm('真的要删除吗？删除后将无法找回！', {
            btn: ['确定','取消'] //按钮
        }, function(){
            myRequestRefresh(self, "{:url('delAll')}", $("#delRecord").serialize());
        }, function(){

        });
    }

    function del(self, id){
        if ($(self).hasClass('ed')) {
            return false;
        }

        layer.confirm('真的要删除吗？删除后将无法找回！', {
            btn: ['确定','取消'] //按钮
        }, function(){
            myRequestRefresh(self, "{:url('del')}", {id:id});
        }, function(){

        });
    }

    $(function(){
        //全选的实现
        $(".check-all").click(function(){
            $(".ids").prop("checked", this.checked);
        });
        $(".ids").click(function(){
            var option = $(".ids");
            option.each(function(i){
                if(!this.checked){
                    $(".check-all").prop("checked", false);
                    return false;
                }else{
                    $(".check-all").prop("checked", true);
                }
            });
        });

    });
    function showSons(self, id) {
        if ($(self).text() <= 0) {
            return false;
        }

        layer.open({
            type: 2,
            title: '查看下级',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: [$(window).width()+'px', $(window).height()+'px'],
            content: "{:url('index')}?pid="+id
        });
    }
</script>
{/block}
{block name='body'}
<body class="gray-bg" >
    <div class="wrapper wrapper-content animated fadeInRight">

        <div class="row" style="overflow-x: scroll;width: 100%;">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>用户管理</h5>
                        <a href="{:url('save')}" class="btn btn-sm btn-primary pull-right m-t-n-xs">添加用户</a>
                    </div>
                   
                    <div class="ibox-content">
						<div class="row">
							<form name="form" action="{:url('index')}" method="get">
                                <!-- <div class="col-sm-1 m-b-xs">
                                    <input type="submit" class="btn btn-sm btn-primary btn-sm btn-danger pull-left" onclick="delAll(this);return false;" value="删除"  />
                                </div> -->

                                <!-- <div class="col-sm-2 m-b-xs">
                                    <select name="type" class="input-sm  form-control">
                                        <option value="-1">等级</option>
                                        {volist name="typeList" id="vo"}
                                        <option value="{$key}" {if condition="input('type', -1, 'intval') eq $key"} selected {/if} >{$vo}</option>
                                        {/volist}
                                    </select>
                                </div> -->
                                <div class="col-sm-4 m-b-xs">
                                    <div class="input-group">
                                        <input type="text" name="keywords" placeholder="姓名/电话" value="{:input('keywords', '', 'trim')}" class="input-sm form-control"> <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                    </div>
                                </div>
							</form>
                        </div>
                        <!-- <xblock style="height: auto;"> -->
                            		<!-- <button class="layui-btn layui-btn-danger stateAll" data-value="true" data-confirm="确认要删除吗？" url="{:URL(request()->controller().'/state',['key'=>'IsLock'])}"><i class="layui-icon"></i>批量删除</button> -->
                            <!-- <a class="layui-btn" onclick="reset_pass(1)"><i class="layui-icon">&#xe673;重置登录密码</i></a>
                            <a class="layui-btn" onclick="reset_pass(2)"><i class="layui-icon">&#xe673;重置支付密码</i></a> -->
                            <!--		<a class="layui-btn" target="_blank" href="{:URL('Member/export',$Request.param)}"><i-->
                            <!--				class="layui-icon layui-icon-download-circle"></i>Excel</a>-->
                            <!-- <span class="x-right" style="line-height:40px">共有数据：{$list->total()} 条</span>
                        </xblock> -->
                        <form name="form" action=""  method="post" id="delRecord">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>
                                        <input class="check-all" type="checkbox" value="">
                                    </th>
                                    <th>ID</th>
                                    <th>姓名</th>

                                    <th>手机号</th>
                                    <th>编号</th>
                                    <th>推荐人编号</th>
                                    <th>推荐人姓名</th>
                                    <th>等级</th>
                                    <th>余额</th>
                                    <!-- <th>usdt地址</th>
                                    <th>欢笑豆</th>
                                    <th>欢乐豆</th> -->
                                    <!-- <th>奖金</th> -->

                                    <th>推广人数</th>
                                    <th>单数</th>

                                    <th>是否锁定</th>
                                    <th>注册时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
								{foreach name="list" item="li"}
                                <tr >
                                    <td><input type="checkbox" class="ids" value="{$li.id}" name="id[]"></td>
                                    <td>{$li.id}</td>

                                    <td>{$li.name|default=''}</td>
                                    <td>{$li.tel|default=''}</td>
                                    <td>{$li.code|default=''}</td>
                                    <td>{$li.referee_code|default='-'}</td>
                                    <td>{$li.p_user|default='-'}</td>
                                    <td>{$li.l_title|default=''}</td>
                                    <td>{$li.balance|default=''}</td>

                                    <!-- <td>{$li.usdt_addr|default=''}</td>

                                    <td>￥{$li.bonus1|default=''}</td>
                                    <td>￥{$li.bonus2|default=''}</td> -->
                                    <!-- <td>￥{$li.bonus|default=''}</td> -->
                                    <!-- onclick="showSons(this, {$li.id});" -->
                                    <td><a href="javascript:;"  class="btn btn-info btn-xs">{$li.has_son|default=0}</a></td>
                                    <td>
                                        {$li.head|default=''}                                     
                                    </td>
                                    <td>
                                        {if condition='$li.locks eq 0'}
                                        <a href="javascript:;" onclick="setLocks(this);" data-id="{$li.id}" data-locks="1" class="btn btn-success btn-xs">否</a>
                                        {else/}
                                        <a href="javascript:;" onclick="setLocks(this);" data-id="{$li.id}" data-locks="0" class="btn btn-danger btn-xs">是</a>
                                        {/if}
                                    </td>
                                    <td>{$li.add_time|date="Y-m-d H:i:s",###}</td>
                                    <td>
                                        <a class="btn btn-success btn-xs" onclick="member_login(this,{$li.id})" href="javascript:;"><i class="fa fa-edit"></i>登录</a>
                                        <a href="{:url('save', ['id'=>$li['id']])}" class="btn btn-success btn-xs edit"><i class="fa fa-edit"></i> 编辑</a>
                                        <a onclick="show('会员充值','{:url(\'edit',['id\'=>$li.id,\'tpl\'=>\'recharge\'])}',500,500)" class="btn btn-success btn-xs edit"><i class="fa fa-edit"></i> 充值</a>
										<a href="javascript:;" onclick="del(this, {$li.id});" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i> 删除</a>
									</td>
                                </tr>
								{/foreach}
                            </tbody>
							<tfoot>
								<tr>
                                    <td colspan="20">
										<div class="zy_page">{$list->render()}</div>
									</td>
                                </tr>
							</tfoot>
                        </table>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
</body>
<script>

function member_login(obj, id) {
    layer.confirm('确认要登录此用户吗？', function (index) {
        $.get(
            "{:URL('Login/web_login')}",
            {id: id},
            function (data) {
                if (data.status == 1) {
                    layer.msg("已登录,正在进入首页...", {time: 500}, function () {
                        window.open("/index.php");
                    });
                }
            }
        );
        //发异步删除数据
        // layer.msg('正在登录，请稍等。',{icon:1,time:1000});
    });
}
function reset_pass(type) {
    let ids = $('.ids:checked').val();
    console.log(ids);return;
    let title;
    if (ids != "") {
        if (type === 1) {
            title = "确定要重置会员的登录密码吗?<br/><span style='color: red;'>默认密码为\"111111\"</span>";
        } else if (type === 2) {
            title = "确定要重置会员的二级密码吗?<br/><span style='color: red;'>默认密码为\"222222\"</span>";
        }
        layer.confirm(title, function (index) {
            $.get("{:url('reset_pass')}", {id: ids, type: type}, function (data) {
                        if (data.status == 1) {
                            layer.msg(data.message, {icon: 1, time: 1000});
                        } else {
                            layer.msg(data.message, {icon: 2, time: 1000});
                        }
                    }
            );
        });
    } else {
        layer.msg("请选择要重置的会员");
    }
}
</script>
{/block}
